package com.samuel.learing.controller.javaBase;

public class Demo {

    public static void main(String[] args) {


        int[] nums = {1, 2, 3, 4, 5, 6};
        arrayReplaceWithGreatestFromRight(nums);

    }

    public static void arrayReplaceWithGreatestFromRight(int[] nums) {


        if (nums.length == 0) {
            return;
        }

        int len = nums.length;
        for (int i = 0; i < len; i++) {

            if (i == nums.length - 1) {
                nums[i] = -1;
                continue;
            }
            int max = nums[i + 1];
            for (int j = i + 1; j < len - i; j++) {
                if (nums[j] > max) {
                    max = nums[j];
                }
            }

            nums[i] = max;
        }
        for (int i = 0; i < nums.length; i++) {
            System.out.println(nums[i]);
        }

    }

}
